package com.cdtye.shuoh.controller.rule;

import com.cdtye.common.webcore.web.AjaxJson;
import com.cdtye.shuoh.domain.rule.entity.Rule;
import com.cdtye.shuoh.domain.rule.vo.RuleVo;
import com.cdtye.shuoh.service.rule.RuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 规则Controller
 * @author ZhongWang Wang
 * @date 2022-12-21
 */
@RestController
@RequestMapping("/rule")
public class RuleController {
    @Autowired
    private RuleService ruleService;

    /**
     * 分页查询
     * @param vo
     * @return
     */
    @PostMapping("/pageList")
    public AjaxJson pageList(@RequestBody RuleVo vo){
        return AjaxJson.success(ruleService.pageList(vo));
    }

    /**
     * 列表获取
     * @param vo
     * @return
     */
    @PostMapping("/list")
    public AjaxJson list(@RequestBody RuleVo vo){
        return AjaxJson.success(ruleService.list(vo));
    }

    /**
     * 插入规则
     * @param rule
     * @return
     */
    @PostMapping("/insertRule")
    public AjaxJson insertRule(@RequestBody Rule rule){
        boolean result = ruleService.insertRule(rule);
        return AjaxJson.success(result);
    }

    /**
     * 更新规则
     * @param rule
     * @return
     */
    @PostMapping("/updateRule")
    public AjaxJson updateRule(@RequestBody Rule rule){
        boolean result = ruleService.updateRule(rule);
        return AjaxJson.success(result);
    }

    /**
     * 根据id获取规则
     * @param id
     * @return
     */
    @GetMapping("/getRuleById")
    public AjaxJson getRuleById(String id){
        return AjaxJson.success(ruleService.getRuleById(id));
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @GetMapping("/deletRuleById")
    public AjaxJson deleteRuleById(String id){
        return AjaxJson.success(ruleService.deleteRuleById(id));
    }
}
